package com.chi.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.chi.comm.Const;
import com.chi.pojo.Advise;
import com.chi.pojo.Leave;
import com.chi.pojo.Leaves;
import com.chi.service.LeaveService;
import com.chi.service.LeavesService;
import com.opensymphony.xwork2.ModelDriven;

@Controller
public class LeaveAction implements ModelDriven<Leave>,RequestAware {
	
	@Autowired
    private LeaveService leaveservice;
    @Autowired
    private LeavesService leavesservice;
    
    
	private Map<String,Object> requestmap;
	private Leave leave=new Leave();
	 private int pageNo;
		
		public int getPageNo() {
			return pageNo;
		}

		public void setPageNo(int pageNo) {
			this.pageNo = pageNo;
		}
	public LeaveAction() {
		super();
	}
	@Override
	public void setRequest(Map<String, Object> arg0) {
		// TODO Auto-generated method stub
		requestmap = arg0;
	}

	public String save(){
		leaveservice.saveLe(leave);
		return "success";}
	public String update(){
		leaveservice.updateLe(leave);
		return "success";}
	public String load(){
		requestmap.put("did", leave.getId());
		return "success";
	}
	public String delete(){
		leaveservice.deleteLd(leave);
		return "success";}
	public String findAll(){
		pageNo = 1;
		List<Leaves> Lea=leavesservice.findAll(pageNo);
		System.out.println(Lea);
		if(Lea!= null && Lea.size() > 0){
			requestmap.put("Leaves", Lea);
			return "success";
		}
		return "bad";
	}
	public String page(){
		List<Leaves> Lea=leavesservice.getPage(pageNo).getList();
		if(Lea!= null && Lea.size() > 0)
		{
			requestmap.put("Leaves", Lea);
			return "success";
		}
		return "bad";
	}
	@Override
	public Leave getModel() {
		// TODO Auto-generated method stub
		return leave;
	}

}
